#include "Tcpserver.hpp"
#include "ServerCal.hpp"

void Usage(std::string s)
{
    std::cout << s << "  [port]" << std::endl;
}

int main(int argc, char* argv[])
{

    if(argc != 2)
    {
        Usage(argv[0]);
        return 1;
    }

    uint16_t port = std::stoi(argv[1]);
    Calculate cal;
    TcpServer* ts = new TcpServer(std::bind(&Calculate::Compute, &cal, std::placeholders::_1), port);
    ts->Init();
    ts->Run();




    // 测试序列化与反序列化是否可以成功
    // Request reqs(123, 456, '+');
    // std::string content;
    // reqs.Serialization(&content);//序列化
    // std::cout << content << std::endl;

    // std::string package = Encode(content);//封装
    // std::cout << package;

    // content = "";
    // Decode(package, &content);//解析
    // std::cout << content << std::endl;

    // reqs.Deserialization(content);
    // std::cout << reqs.x << std::endl;
    // std::cout << reqs.op << std::endl;
    // std::cout << reqs.y << std::endl;




    // Response resp(100, 0);
    // content = "";
    // resp.Serialization(&content);//序列化
    // std::cout << content << std::endl;


    // package = Encode(content);
    // std::cout << package;

    // Decode(package, &content);
    // std::cout << content << std::endl;

    // resp.Deserialization(content);
    // std::cout << resp._result << std::endl;
    // std::cout << resp._code << std::endl;
    
    return 0;
}